package innerclass;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-10-25
 * Time:9:57
 */
/*
 1.如何得到静态内部类的对象
         OuterClass1.InnerClass innerClass = new OuterClass1.InnerClass();
         2.在静态内部类中不能使用外部类的普通成员变量
         非要使用?在静态内部类中实例化一个外部类对象，通过这个引用来访问
         3.通过外部类名.静态成员变量 来访问外部类的静态成员变量
 */
class OuterClass1{
    public int data1 = 1;
    public static int data2 = 2;
    private int data3 = 3;

    static class InnerClass{
//        public OuterClass1 out2 = new OuterClass1();
        public int data1 = 1111;
        public int data4 = 4;
        public int data2 = 2222;
        public static  final int data5 = 5;//
        OuterClass1 out2;
        public InnerClass(OuterClass1 o){
            this.out2 = o;
        }
        private int data6 = 6;
        public void  func(){
            System.out.println("这是一个实例内部类的func方法");
            System.out.println(out2.data1);
            System.out.println(this.data1);
            System.out.println(OuterClass1.data2);
            System.out.println(out2.data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}
class Demo{
    public void func(){
        System.out.println("demo: func");
    }
}
//匿名的内部类
public class TestDemo2 {
    public static void main(String[] args) {
        new Demo(){
            @Override
            public void func(){
                System.out.println("这是匿名内部类的func方法");
            }
        }.func();
    }
    public static void main1(String[] args) {
        OuterClass1 outerClass1 = new OuterClass1();
        OuterClass1.InnerClass innerClass = new OuterClass1.InnerClass(outerClass1);
        innerClass.func();
    }
}
